package com.codingday.app;

import java.util.Date;

import android.content.ComponentName;
import android.content.Context;
import android.content.ServiceConnection;
import android.location.Location;
import android.os.IBinder;
import android.util.Log;

public class TODO {

	long TODO_ID;
	Date createdDate;
	Date completedDate;
	
	boolean isEnabled = true;
	String title = null;
	String desc = null;
	
	double latitude;
	double longitude;
	int radius;	// meter
	
	boolean isPaused;
	boolean isCompleted;

	public TODO(){
		
	}
	
	public TODO(String title, String desc){
		this.title = title;
		this.desc = desc;
		radius = 300;
		isPaused =  false;
		
	}
	
	public void setID(long ID){
		TODO_ID = ID;
		//createdDate = date;
	}
	
	public long getID(){
		return TODO_ID;
	}
	
	public String getTitle(){
		return title;
	}
	public String getDesc(){
		return desc;
	}
	public synchronized void setTitle(String title){
		this.title = title;
	}
	public synchronized void setDesc(String desc){
		this.desc = desc;
	}
	
	public synchronized void setLocation(double latitude, double longitude, int radius){
		this.latitude = latitude;
		this.longitude = longitude;
		this.radius = radius;
	}
	
	public synchronized void checkCreatedInArea(){
		// check this TODO is in Radius or Not
		// Do not need to check!!
		this.isPaused = true;
	}


	public boolean isPausedByInitial(){
		return isPaused;
	}
	
	
	public synchronized void resumeFromInitialPause(boolean resume){
		isPaused = !resume;
		SaveManager.updateTODO(this);
	}
	

	public int getRadius(){
		return radius;
	}
	
	public double getLatitude(){
		return latitude;
	}
	public double getLongitude(){
		return longitude;
	}
	public boolean isCompleted(){
		return isCompleted;
	}
	public boolean isEnabled(){
		return isEnabled;
	}
	
	public synchronized void setCompleted(boolean completed){
		this.isCompleted = completed;
		if(completed){
			this.isEnabled = false;
			this.isPaused = false;
			SaveManager.FinishTODO(this);


		}else{
			this.isEnabled = true;
			this.isPaused = true;
			this.completedDate = null;
			SaveManager.updateTODO(this);
		}
		GeoAlarm.getInstance().getService();
		GeoAlarmService.resetService();
	}


	public synchronized void setStatusFromDB(boolean enabled, boolean paused, boolean completed){
		this.isEnabled = enabled;
		this.isPaused = paused;
		this.isCompleted = completed;
	}

	
	public synchronized void Enable(){
		if(this.isCompleted){
			return;
		}
		isEnabled = true;
		SaveManager.updateTODO(this);
		Log.i("TODO","Enable() :"+this.getTitle()+"("+this.getID()+")");
		//GeoAlarm.getInstance().getService();
		GeoAlarmService.resetService();
	}
	public synchronized void Disable(){
		isEnabled = false;
		SaveManager.updateTODO(this);

		//GeoAlarm.getInstance().getService();
		GeoAlarmService.resetService();
	}
	
	public synchronized void setCreatedDate(Date date){
		this.createdDate = date;
	}
	public synchronized void setCompletedDate(Date date){
		this.completedDate = date;
	}
	
	public Date getCreatedDate(){
		return this.createdDate;
	}
	public Date getCompletedDate(){
		return this.completedDate;
	}
	
}
